public class Complex {
    int RealPart;
    int ImagePart;
    public Complex(){}
    public Complex(int R,int I){
        RealPart = R;
        ImagePart = I;
    }
    public int getRealPart(){
        return RealPart;
    }
    public int getImagePart(){
        return ImagePart;
    }
    public String toString(){
        String s = new String();
        if(ImagePart>0)
            s = getRealPart()+"+"+getImagePart()+"i";
        if(ImagePart==0)
            s = getRealPart()+"";
        if(ImagePart<0)
            s = getRealPart()+""+getImagePart()+"i";
        if(RealPart==0)
            s = getImagePart()+"i";
        if(ImagePart==0&&RealPart==0)
            s = "0";
        return s;
    }
    public Complex ComplexAdd(Complex a){
        Complex d = new Complex();
        d.RealPart = RealPart + a.RealPart;
        d.ImagePart = ImagePart + a.ImagePart;
        return d;
    }
    public Complex ComplexSub(Complex a){
        Complex d = new Complex();
        d.RealPart = RealPart - a.RealPart;
        d.ImagePart = ImagePart - a.ImagePart;
        return d;
    }
    public Complex ComplexMulti(Complex a){
        Complex d = new Complex();
        d.RealPart = RealPart*a.RealPart - ImagePart*a.ImagePart;
        d.ImagePart = RealPart*a.ImagePart + ImagePart*a.RealPart;
        return d;
    }
    public Complex ComplexDiv(Complex a) {
        Complex d = new Complex();
        d.RealPart = (RealPart * a.RealPart + ImagePart * a.ImagePart) / (a.RealPart * a.RealPart + a.ImagePart * a.ImagePart);
        d.ImagePart = (ImagePart * a.RealPart - RealPart * a.ImagePart) / (a.RealPart * a.RealPart + a.ImagePart * a.ImagePart);
        return d;
    }
}